const scannerCfgs = {
  base: {
    1: -1, // CAP_XFERCOUNT -1=-1: 1=1
    256: 6, // ICAP_COMPRESSION 0=None	Enumeration	1  5:tiff  6:jpeg/tiff 8:grayscale tiff  12:bmp
    257: 2, // √ ICAP_PIXELTYPE 0,bw 1,gray 2,rgb
    259: 1, // ICAP_XFERMECH 0=Native: 1=File: 2=Memory
    4098: 1, // CAP_FEEDERENABLED
    4103: 1, // CAP_AUTOFEED
    4112: 1, // CAP_AUTOSCAN
    4115: 1, // CAP_DUPLEXENABLED 0=False: 1=True
    4352: 1, // ICAP_AUTOBRIGHT
    4364: 4, // x  ICAP_IMAGEFILEFORMAT 0,tiff 2,bmp 4,jpg 6itffmulti
    4376: 150, // ICAP_XRESOLUTION
    4377: 150, // ICAP_YRESOLUTION
    4386: 11, //ICAP_SUPPORTEDSIZES
    4395: 24, // ICAP_BITDEPTH  GRAY:4/8  RGB:24/48
    4404: 1, // ICAP_AUTODISCARDBLANKPAGES
    4432: 1, // ICAP_AUTOMATICBORDERDETECTION
    4433: 1, // ICAP_AUTOMATICDESKEW
  },
  // 'Canon DR-6030C TWAIN:1'
  canon: {
    4385: 270.0, // ICAP_ROTATION
    4435: 100, // ICAP_JPEGQUALITY
  },
  // PaperStream IP fi-7480:3
  // PaperStream IP fi-7600:2
  paperstream: {
    opts: {
      reverse: 1,
    },
    4435: 20, // ICAP_JPEGQUALITY
  },
  //虹光 AD6090:1
  ad6090: {
    4406: 1, // ICAP_FLIPROTATION 图片每隔一张翻转一次方向
    4435: 15, // ICAP_JPEGQUALITY
  },
  //虹光 aw6380+
  'aw6380+': {
    4385: 270.0, // ICAP_ROTATION
    4406: 1, // ICAP_FLIPROTATION 图片每隔一张翻转一次方向
    4435: 15, // ICAP_JPEGQUALITY
  },
};

const getFromHttp = async (name, brand) => {
  // 可以从系统字典接口去
  // dictKey=scanner
  throw new Error(`请实现从后台获取配置 name:${name} brand:${brand}`);
};

/**
 * 获取扫描仪配置
 * @param {string} ds  扫描仪名称
 */
export const getCfg = async ds => {
  if (!ds) {
    throw new Error('请输入扫描仪源');
  }
  let idx = ds.lastIndexOf(':');
  if (idx < 0) {
    idx = ds.length;
  }
  const name = ds.substring(0, idx);
  const brand = name.split(' ')[0];
  let cfg = scannerCfgs[name] || scannerCfgs[brand];
  if (!cfg) {
    cfg = await getFromHttp(name, brand);
  }
  if (!cfg) {
    cfg = await getFromHttp(`debug-${new Date().getDay()}`);
  }
  if (!cfg) {
    throw new Error('当前扫描仪暂不支持,可以联系客服进行技术支持');
  }
  return { ...scannerCfgs.base, ...cfg };
};
